package org.example.copy.DeepCopy;

import lombok.Data;

@Data
class Person implements Cloneable {
    private String name;
    private Address address;
    public Person(String name, Address address) {
        this.name = name;
        this.address = address;
    }
    // 实现克隆方法以进行深拷贝
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person cloned = (Person) super.clone(); // 先调用Cloneable类中的super.clone()进行浅拷贝
        cloned.address = (Address) this.address.clone(); // 然后递归地对Address对象进行深拷贝
        return cloned;
    }
}